package frc.circuitrunners;

/**
 * @author CircuitRunners
 * This is the base architecture of all subsystems of the robot ala drive train, fetcher, etc.
 */
public abstract class RobotSubsystem {
    public static int stage, STATE;
    private static boolean autonomousDone = false;
    public boolean flag;
    private static byte flagByte = 0;
    public static final int MAX_NUM_STAGES = 3, AUTONOMOUS = 0, TELEOP_NORMAL = 1, AUTOAIM = 2, AUTOBALANCE = 3, DISABLED = 4;
    public final void run(){
        switch(STATE){
            case AUTONOMOUS:
                if(!autonomousDone){
                    if(flag){
                        flagByte++;
                        if(Scheduler.currentFiber == Scheduler.fibers.length){
                            if(flagByte == Scheduler.fibers.length){
                                stage++;
                                for(int j = 0; j < Scheduler.fibers.length; j++){
                                    Scheduler.fibers[j].flag = false;//Resets all the fibers' flags
                                }
                            }
                            flagByte = 0;
                        }
                    } else {
                        autonomous();
                    }
                    if(stage >= MAX_NUM_STAGES){
                        autonomousDone = true;
                    }
                }
                break;
            case TELEOP_NORMAL:
                teleop();
                break;
            case AUTOAIM:
                autoAim();
                break;
            case AUTOBALANCE:
                //autoBalance();
                break;
            case DISABLED:
                disable();
                break;
        }
    }
    
    /*
     * In autonomous, this will run a certain stage in the process
     *@param stage the stage to run
     */
    public abstract void autonomous();
    /*
     * Initialize the states of each subsystem
     */
    public abstract void init();
    
    /*
     * What should be executed for a subsystem in Teleoperated period
     */
    public abstract void teleop();
    
    /**
     * What the subsystem will do when the robot is disabled
     */
    public abstract void disable();

    /**
     * What The robot subsysem is to do when auto aiming
     */
    public abstract void autoAim();
    
    public abstract void autoBalance();
}
